package com.basemap.GZtianditu;/*
 * Copyright 2017 wshunli
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */



import com.esri.arcgisruntime.arcgisservices.LevelOfDetail;
import com.esri.arcgisruntime.geometry.Point;
import com.esri.arcgisruntime.geometry.SpatialReference;

import java.util.ArrayList;
import java.util.List;

public class GZLayerInfoFactory {
//    private static String key = "b1b55f2720244fd6b6c2ba46a3f3a6be"; //贵州天地图
//
//    static {
//        if (BaseMapApi.getInstance().getGzTdtTK() != null) {
//            key = BaseMapApi.getInstance().getGjTdtTK();
//        }
//    }

    private static final String URL_IMAGE_GZ_2023 = "http://61.243.3.233:8034/arcgis/rest/services/GZS2023DOM1/MapServer/WMTS"; //2023年亚米级影像
    private static final String URL_IMAGE_GZ_2022 = "http://61.243.3.233:8034/arcgis/rest/services/GZS2022DOM3/MapServer/WMTS"; //2022年亚米级影像
    private static final String URL_IMAGE_GZ_2000 = "http://61.243.3.233:8034/arcgis/rest/services/GZS2021DOM3/MapServer/WMTS"; //2021年亚米级影像
    private static final String URL_IMAGE_GZ2020_2000 = "http://61.243.3.233:8034/arcgis/rest/services/GZS2020DOM3/MapServer/WMTS"; //2020年亚米级影像
    private static final String URL_IMAGE_GZ2019_2000 = "http://61.243.3.233:8034/arcgis/rest/services/GZS2019DOM2/MapServer/WMTS"; //2019年影像
    private static final String URL_IMAGE_GZ2018_2000 = "http://61.243.3.233:8034/arcgis/rest/services/GZS2018DOM2/MapServer/WMTS"; //2018年影像
    private static final String URL_IMAGE_GZ_ANNOTATION_CHINESE_2000 = "http://61.243.3.233:8034/arcgis/rest/services/cia2021_c/MapServer/WMTS";


    private static final String LAYER_NAME_IMAGE_GZ2023 = "GZSYX2023DOM3";
    private static final String LAYER_NAME_IMAGE_GZ2022 = "GZSYX2022DOM3";
    private static final String LAYER_NAME_IMAGE_GZ = "GZSYX2021DOM3";
    private static final String LAYER_NAME_IMAGE_GZ2020 = "GZSYX2020DOM3";
    private static final String LAYER_NAME_IMAGE_GZ2019 = "GZSYX2019DOM2";
    private static final String LAYER_NAME_IMAGE_GZ2018 = "GZSYX2018DOM2";
    private static final String LAYER_NAME_IMAGE_GZ_ANNOTATION_CHINESE = "cia2021_c";

    private static final String TILE_MATRIX_SET_GZ_2000 = "default";

    private static final int SRID_2000 = 4490;
    private static final Point ORIGIN_2000 = new Point(-180, 90,
            SpatialReference.create(GZLayerInfoFactory.SRID_2000));
    private static final double X_MIN_2000 = -180;
    private static final double Y_MIN_2000 = -90;
    private static final double X_MAX_2000 = 180;
    private static final double Y_MAX_2000 = 90;

    private static final double[] SCALES = {400000000, 295497598.5708346, 147748799.285417,
            73874399.6427087, 36937199.8213544, 18468599.9106772,
            9234299.95533859, 4617149.97766929, 2308574.98883465,
            1154287.49441732, 577143.747208662, 288571.873604331,
            144285.936802165, 72142.9684010827, 36071.4842005414,
            18035.7421002707, 9017.87105013534, 4508.93552506767, 2254.467762533835};//

    private static final double[] RESOLUTIONS_2000 = {0.7031249999891485,
            0.35156249999999994, 0.17578124999999997, 0.08789062500000014,
            0.04394531250000007, 0.021972656250000007, 0.01098632812500002,
            0.00549316406250001, 0.0027465820312500017, 0.0013732910156250009,
            0.000686645507812499, 0.0003433227539062495,
            0.00017166137695312503, 0.00008583068847656251,
            0.000042915344238281406, 0.000021457672119140645,
            0.000010728836059570307, 0.000005364418029785169,
            2.682209014892579e-006, 1.3411045074462895e-006};

    private static List<LevelOfDetail> getLodsGZ2000() { //贵州天地图
        List<LevelOfDetail> list = new ArrayList<>();
        list.add(new LevelOfDetail(0, 1.4078260157100582, 5.91657527591555E8));
        list.add(new LevelOfDetail(1, 0.7031250000000002, 2.9549759305875003E8));
        list.add(new LevelOfDetail(2, 0.3515625000000001, 1.4774879652937502E8));
        list.add(new LevelOfDetail(3, 0.17578125000000006, 7.387439826468751E7));
        list.add(new LevelOfDetail(4, 0.08789062500000003, 3.6937199132343754E7));
        list.add(new LevelOfDetail(5, 0.043945312500000014, 1.8468599566171877E7));
        list.add(new LevelOfDetail(6, 0.021972656250000007, 9234299.783085939));
        list.add(new LevelOfDetail(7, 0.010986328125000003, 4617149.891542969));
        list.add(new LevelOfDetail(8, 0.005493164062500002, 2308574.9457714846));
        list.add(new LevelOfDetail(9, 0.002746582031250001, 1154287.4728857423));
        list.add(new LevelOfDetail(10, 0.0013732910156250004, 577143.7364428712));
        list.add(new LevelOfDetail(11, 6.866455078125002E-4, 288571.8682214356));
        list.add(new LevelOfDetail(12, 3.433227539062501E-4, 144285.9341107178));
        list.add(new LevelOfDetail(13, 1.7166137695312505E-4, 72142.9670553589));
        list.add(new LevelOfDetail(14, 8.583068847656253E-5, 36071.48352767945));
        list.add(new LevelOfDetail(15, 4.2915344238281264E-5, 18035.741763839724));
        list.add(new LevelOfDetail(16, 2.1457672119140632E-5, 9017.870881919862));
        list.add(new LevelOfDetail(17, 1.0728836059570316E-5, 4508.935440959931));
        list.add(new LevelOfDetail(18, 5.364418029785158E-6, 2254.4677204799655));
        list.add(new LevelOfDetail(19, 2.682209014892579E-6, 1127.2338602399827));
        list.add(new LevelOfDetail(20, 1.3411045074462895E-6, 563.6169301199914));
        return list;
    }

    public static GZTianDiTuLayerInfo getLayerInfo(int layerType) {
        GZTianDiTuLayerInfo layerInfo = new GZTianDiTuLayerInfo();
        switch (layerType) {
            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ_2000://2021年
                layerInfo
                        .setUrl(GZLayerInfoFactory.URL_IMAGE_GZ_2000);
                layerInfo
                        .setLayerName(GZLayerInfoFactory.LAYER_NAME_IMAGE_GZ);
                break;
            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ2020_2000://2020年
                layerInfo
                        .setUrl(GZLayerInfoFactory.URL_IMAGE_GZ2020_2000);
                layerInfo
                        .setLayerName(GZLayerInfoFactory.LAYER_NAME_IMAGE_GZ2020);
                break;
            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ2019_2000://2019年
                layerInfo
                        .setUrl(GZLayerInfoFactory.URL_IMAGE_GZ2019_2000);
                layerInfo
                        .setLayerName(GZLayerInfoFactory.LAYER_NAME_IMAGE_GZ2019);
                break;
            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ2018_2000://2018年
                layerInfo
                        .setUrl(GZLayerInfoFactory.URL_IMAGE_GZ2018_2000);
                layerInfo
                        .setLayerName(GZLayerInfoFactory.LAYER_NAME_IMAGE_GZ2018);
                break;
            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ2022://2022年
                layerInfo
                        .setUrl(GZLayerInfoFactory.URL_IMAGE_GZ_2022);
                layerInfo
                        .setLayerName(GZLayerInfoFactory.LAYER_NAME_IMAGE_GZ2022);
                break;
            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ2023://2022年
                layerInfo
                        .setUrl(GZLayerInfoFactory.URL_IMAGE_GZ_2023);
                layerInfo
                        .setLayerName(GZLayerInfoFactory.LAYER_NAME_IMAGE_GZ2023);
                break;

            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ_ANNOTATION_CHINESE_2000:
                layerInfo.setUrl(GZLayerInfoFactory.URL_IMAGE_GZ_ANNOTATION_CHINESE_2000);
                layerInfo.setLayerName(GZLayerInfoFactory.LAYER_NAME_IMAGE_GZ_ANNOTATION_CHINESE);
                break;
        }
        handleLayerInfo(layerInfo, layerType);
        return layerInfo;
    }

    private static void handleLayerInfo(GZTianDiTuLayerInfo layerInfo,
                                        int layerType) {
        switch (layerType) {
            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ_2000: //贵州天地图2021亚米级
            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ2020_2000: //2020
            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ2019_2000: //2019
            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ2018_2000: //2018
            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ2022:
            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ2023:
            case GZTianDiTuLayerTypes.TIANDITU_IMAGE_GZ_ANNOTATION_CHINESE_2000: //贵州天地图标注
                layerInfo.setOrigin(GZLayerInfoFactory.ORIGIN_2000);
                layerInfo.setSrid(GZLayerInfoFactory.SRID_2000);
                layerInfo.setxMin(GZLayerInfoFactory.X_MIN_2000);
                layerInfo.setyMin(GZLayerInfoFactory.Y_MIN_2000);
                layerInfo.setxMax(GZLayerInfoFactory.X_MAX_2000);
                layerInfo.setyMax(GZLayerInfoFactory.Y_MAX_2000);
                layerInfo.setScales(GZLayerInfoFactory.SCALES);
                layerInfo.setResolutions(GZLayerInfoFactory.RESOLUTIONS_2000);
                layerInfo.setTileMatrixSet(GZLayerInfoFactory.TILE_MATRIX_SET_GZ_2000);
                layerInfo.setLods(getLodsGZ2000());
                break;
        }
    }
}
